package service;

import model.User;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SelectFriends {

    public List<Integer> selectFriends(Integer id) {
        List<Integer> list = new ArrayList<Integer>();
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            connection = JDBCConnect.getConnection();
            String sql = "select friendid from user_friends where id = ?";
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1, id);
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                int friendid = resultSet.getInt(1);
                list.add(friendid);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
